//点击登陆/注册，弹出登陆/注册框
var  landbox = document.querySelector("header section div div")
landbox.onclick = function(){
    document.querySelector("body section:nth-of-type(2)").style.visibility="visible"
}

//点击登陆/注册框中的X关闭登陆/注册框
var closelandbox = document.querySelector("body section:nth-of-type(2) .icon-close")
closelandbox.onclick=function(){
    document.querySelector("body section:nth-of-type(2)").style.visibility="hidden"
}

//登录框实现拖动功能
var landbigbox = document.querySelector("body section:nth-of-type(2) div.item div.menu")
landbigbox.onmousedown=function(evt){
    var evt = evt || window.event
    document.onmousemove=function(e){
        var e = e || window.event
        var movelandbox=document.querySelector("body section:nth-of-type(2) div")
        var left = e.clientX - evt.offsetX
        var top =  e.clientY - evt.offsetY
        if(left < 0) left=0
        if(top < 0) top = 0
        var temp = document.querySelector("section.login div.item")
        var maxleft = window.innerWidth - temp.offsetWidth
        var maxtop = window.innerHeight - temp.offsetHeight
        if(left > maxleft) left=maxleft
        if(top > maxtop) top = maxtop
        movelandbox.style.position = "absolute"
        movelandbox.style.left = left + "px"
        movelandbox.style.top = top + "px"
    }
document.onmouseup=function(){
    document.onmousemove=null
}
}



//行为验证码框显示和点击关闭
var yzm = document.querySelector("body section.login div.item div.form button.captcha")
yzm.onclick=function(){
    var captcha = document.querySelector("section.captcha")
    captcha.style.visibility = "visible"
    var captchaclose = document.querySelector("body section.captcha h2 i.icon-close")
    captchaclose.onclick = function(){
        captcha.style.visibility = "hidden"
    }

//行为验证码验证
var dragbox = document.querySelector("section.captcha div.drag div.btn")
dragbox.onmousedown = function(evt){
    console.log(evt.clientX);
    document.onmousemove = function(evt){
        var e = evt || window.event
        console.log(e.clientX);
        var left = e.clientX - 782
        leftdata = left
        if(left < 0)  left = 0
        if(left > 350)  left = 350
        dragbox.style.left = left + "px"
        console.log(left);
        document.querySelector("section.captcha div.check img:nth-of-type(2)").style.left = left + "px"
    }
    document.onmouseup = function()
    {
        document.onmousemove = null
        var leftbut = parseInt(document.querySelector(".captcha .drag .btn").style.left)
        if(leftbut < 260 || leftbut > 265) 
        {
            document.querySelector(".captcha .drag .btn").style.left = "0px"
            document.querySelector("section.captcha div.check img:nth-of-type(2)").style.left = "0px"
        }
        else 
        {
        yzmbox = document.querySelector("body section.login div div.form button.captcha")
        document.querySelector("body section.captcha").style.visibility = "hidden"
        var sum=5
        yzmbox.disabled = true
        yzmbox.innerText = sum+"秒后重新发送"
        t=setInterval(function(){
        sum--
        if(sum<1) 
         {
             clearInterval(t)
             yzmbox.innerText = "重新发送"
             sum=5
             yzmbox.disabled = false
             return
        }
        yzmbox.innerText = sum+"秒后重新发送"
        },1000) 
        }
     }
  }
}


//表单验证

var formlandbox = document.querySelector("section.login button.submit")
formlandbox.onclick = function(){
    var num2=0
    var mobilebox = document.querySelector("section.login input.mobile")
    if(mobilebox.value.length != 11 || mobilebox.value == ""  || !Number(mobilebox.value))
    {
        document.querySelector("section.login div.item div.form p:nth-of-type(3)").innerText = "请输入正确手机号"
    }
    else
    {
        num2++
        document.querySelector("section.login div.item div.form p:nth-of-type(3)").innerText = ""
    }

    var passwordbox = document.querySelector("section.login input.password")
    if(passwordbox.value.length != 4 || passwordbox.value == ""  || !Number(passwordbox.value))
    {
        document.querySelector("section.login div.item div.form p:nth-of-type(4)").innerText = "请输入正确验证码"
    }
    else
    {
        num2++
        document.querySelector("section.login div.item div.form p:nth-of-type(4)").innerText = ""
    }
    
    if(num2 == 2) alert("登陆成功")
}


//无缝滚动
var marginnum = 0
var firstul = document.querySelector(".hot ul.hotclass1")
setInterval(function(){
    marginnum--
    firstul.style.marginLeft = marginnum + "px"
    if(marginnum < -2028) marginnum = 0
},30)



//轮播图
// var lbtnum = 2
// var imglbt = document.querySelector("section.lbt img")
// setInterval(function(){
//     imglbt.src = "./assets/imgs/b"+lbtnum+".jpeg"
    
//     var divall = document.querySelectorAll("section.lbt div.onebox div")
//     divall.forEach(function(item,index){
//         divall[index].style=null
//     })
//     divall[lbtnum-1].style="background:blue"  
//     lbtnum++
//     if(lbtnum == 7) lbtnum=1 
// },2000)


//轮播图按钮点击切换
// var leftlbtclick = document.querySelector("section.lbt div.lbtclick div:nth-of-type(1)")
// leftlbtclick.onclick = function(){
//     console.log(lbtnum);
//     if(lbtnum == 1) 
//     {
//         lbtnum = 6
//     }
//     else
//     {
//         lbtnum -= 1
//         imglbt.src = "./assets/imgs/b"+lbtnum+".jpeg"
//         var divall = document.querySelectorAll("section.lbt div.onebox div")
//         divall.forEach(function(item,index){
//         divall[index].style=null
//     })
//     divall[lbtnum-1].style="background:blue" 
//     }
// }
// var leftlbtclick = document.querySelector("section.lbt div.lbtclick div:nth-of-type(2)")
// leftlbtclick.onclick = function(){
//     console.log(lbtnum);
//     if(lbtnum == 6) 
//     {
//         lbtnum = 1
//     }
//     else
//     {
//         lbtnum += 1
//         imglbt.src = "./assets/imgs/b"+lbtnum+".jpeg"
//         var divall = document.querySelectorAll("section.lbt div.onebox div")
//         divall.forEach(function(item,index){
//         divall[index].style=null
//     })
//     divall[lbtnum-1].style="background:blue" 
//     }
// }



//顶部加载条
var loadbox = document.createElement("div")
loadbox.style.position = "fixed"
loadbox.style.top = 0
loadbox.style.width = "0%"
loadbox.style.height = "1px"
loadbox.style.backgroundColor = "blue"
document.body.appendChild(loadbox)
loadboxwidth = 5
loadboxover = false
var nprogressRadius = document.createElement("div")
nprogressRadius.className = "nprogressRadius"
document.body.appendChild(nprogressRadius)
t=setInterval(function(){
if(loadboxwidth > 95 && !loadboxover) return    
loadboxwidth++
loadbox.style.width = loadboxwidth + "%"

if(loadboxwidth > 100) 
{
    clearInterval(t)
    loadbox.style.display = "none"
    document.querySelector(".nprogressRadius").style.display = "none"
    return
}
},10)





//网页加载进度条等待优化
window.onload = function(){
    loadboxover = true
}